#!/usr/bin/env bash
sudo yum install -y wget
esver=7.15.2-x86_64
wget -c https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$esver.rpm
sudo rpm -ivh elasticsearch-$esver.rpm
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
### 由于我的数据盘在/data里，因此要把elk的数据和日志修改到这个路径,你们可以酌情修改
mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/logs
chown -R elasticsearch:elasticsearch /data/elasticsearch/
sed -i 's%\/var\/lib\/elasticsearch%\/data\/elasticsearch\/data%g' /etc/elasticsearch/elasticsearch.yml
sed -i 's%\/var\/log\/elasticsearch%\/data\/elasticsearch\/logs%g' /etc/elasticsearch/elasticsearch.yml
## 必须设置了集群才能正常的启动。所以单台就下面的设置就好了。多台可以配置多台集群
cat >>/etc/elasticsearch/elasticsearch.yml<<EOF
network.host: 0.0.0.0
discovery.seed_hosts: ["0.0.0.0"]
node.master: true
cluster.name: TestCluster
node.name: node-1
cluster.initial_master_nodes: ["node-1"]
EOF
# 开放端口
firewall-cmd --zone=public --permanent --add-port=9200/tcp
firewall-cmd --reload
sudo systemctl restart elasticsearch.service